define([
    'jquery',
    'underscore',
    'backbone',
    ], function($, _, Backbone){
        var $html_loadding = '<div class="caculation-report" style="text-align:center"><img src="'+$template_admincp_url+'images/preloaders/blue/4.gif"/></div>';
        var shipView = Backbone.View.extend({
            el: $("#main"),
            initialize: function(){
				
            },
            events: {
                
            },
            
            view: function(){
                var url = location.href;
                if(typeof oTable != "undefined"){
                    $("#table_ship").dataTable().fnDestroy();
                }
                oTable = $('#table_ship').dataTable({
                   "sDom": "<'row'<'col-lg-8'l><'col-lg-1 button_create'><'col-lg-3'f>r>t<'row'<'col-lg-6'i><'col-lg-6'p>>",
                    "sPaginationType": "full_numbers",
                    "iDisplayLength": 10,
                    "iDisplayStart": 0,
                    "bProcessing": true,
                    "bRetrieve": true,
                    "bServerSide": true,
                    "sAjaxSource": url,
                    "fnServerData": function(sSource, aoData, fnCallback, oSettings) {
                        if(typeof filters != "undefined"){
                            obj_tmp = new Object;
                            $.each(filters, function(name, value){
                                obj_tmp[name] = value;
                            });
                            aoData.push({
                                name: "myFilter",
                                value: JSON.stringify(obj_tmp)
                            });
                        }
                        $.ajax( {
                            "dataType": 'json',
                            "type": "POST",
                            "url": sSource,
                            "data": aoData,
                            success: function(rs){
                                ids = rs.my_id;
                                fnCallback(rs);
                            }
                        });

                    },
                    "aoColumns": [
                        {
                            // "mData": "admin_name",
                            "sType": "string",
                            "swidth": "25%",
                            "sClass": "string",
                            "sName": "title"
                        },
                        {
                            // "mData": "admin_name",
                            "sType": "string",
                            "swidth": "25%",
                            "sClass": "string",
                            "sName": "description"
                        },
                        {
                            // "mData": "action",
                            "sType": "string",
                            "swidth": "3%",
                            "sClass": "center",
                            "bSortable": false
                        }
                    ],

                    fnInitComplete: function()
                    {
                        $(this).slideDown(200);
                        $(".button_create").html('<button class="btn btn-primary btn-create" type="button">Create New</button>');
                        $(".btn-create").click(function(){
                            window.location.href = $admincp_url+'ship/add';
                        });
                    }
                });
            },

            add: function(){
                // $("#form").validate({
                //     ignore: null,
                //     ignore: 'input[type="hidden"]',
                //     submitHandler: function(form){
                //         form.submit();
                //     }
                // });
            },

            edit: function(){
                // $("#form").validate({
                //     ignore: null,
                //     ignore: 'input[type="hidden"]',
                //     submitHandler: function(form){
                //         form.submit();
                //     }
                // });
            },

            render: function(){
                if(typeof this[$app.action] != 'undefined'){
                    new this[$app.action];
                }
            }
        });
        return shipView = new shipView;
    });
